package com.study.zjh.smartrefreshdemo;

import android.app.Activity;
import android.app.Application;
import android.os.Environment;

import com.billy.android.swipe.SmartSwipeBack;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        setChangeActivity();
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
    }

    private void setChangeActivity(){
        //        SmartSwipeBack.activityBezierBack(this, null);    //仿小米MIUI系统的贝塞尔曲线返回效果
        SmartSwipeBack.activityDoorBack(this, new SmartSwipeBack.ActivitySwipeBackFilter() {
            @Override
            public boolean onFilter(Activity activity) {
                return !(activity instanceof MainActivity);
            }
        });
//        SmartSwipeBack.activityStayBack(application, null);        //仿手机QQ的手势滑动返回
//        SmartSwipeBack.activitySlidingBack(this, null);    //仿微信带联动效果的透明侧滑返回
//        SmartSwipeBack.activityDoorBack(this, null);        //侧滑开门样式关闭activity
//        SmartSwipeBack.activityShuttersBack(this, null);    //侧滑百叶窗样式关闭activity
    }

    // 异常捕获处理器
    private class MyUncaughtExceptionHandler implements
            Thread.UncaughtExceptionHandler {

        @Override
        public void uncaughtException(Thread thread, Throwable ex) {

            try {
                // 把错误日志保存到sdcard
                File file = new File(Environment.getExternalStorageDirectory(),
                        "carch_123.txt");
                PrintWriter err = new PrintWriter(file);
                ex.printStackTrace(err);
                err.flush();
                err.close();

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // 早死早超生
//            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(0);

        }

    }
}
